package meconsea.life.cms.util;

import java.util.ArrayList;
import java.util.List;

import meconsea.life.cms.entity.Article;
import meconsea.life.cms.entity.SArticle;
import meconsea.life.cms.entity.VArticle;
import meconsea.life.util.Constant;

import org.json.JSONArray;
import org.json.JSONObject;

public class CMSUtil {
	public static List<? extends Article> parseObjToArt(List<Object[]> args,String artType){
		List<? extends Article> res = new ArrayList();
		for(Object[] _t :args){
			Article art_ = null;
			if(artType.equals(Constant.ART_TYPE_ALL)){
				art_ = new VArticle();
			}else if(artType.equals(Constant.ART_TYPE_S)){
				art_ = new SArticle();
			}
		}
		return res;
	}
	public static JSONArray parseArtToJSON(List<Object[]> arts,boolean artType)throws Exception{
		JSONArray res = new JSONArray();
		for(Object[] _t : arts){
			JSONObject _tJ = new JSONObject();
			_tJ.put("id",_t[0]);
			_tJ.put("title",_t[1]);
			_tJ.put("subtitle",_t[2]);
			_tJ.put("keywords",_t[3]);
			_tJ.put("summary",_t[4]);
			_tJ.put("specialId",_t[5]);
			_tJ.put("artClass",_t[6]);
			_tJ.put("artClassName",_t[7]);
			_tJ.put("artClassPath",_t[8]);
			_tJ.put("indexImg",_t[9]);
			_tJ.put("homeImg",_t[10]);
			_tJ.put("artResource",_t[11]);
			_tJ.put("author",_t[12]);
			_tJ.put("commend",_t[13]);
			_tJ.put("top",_t[14]);
			_tJ.put("hot",_t[15]);
			_tJ.put("comment",_t[16]);
			_tJ.put("clicks",_t[17]);
			_tJ.put("statusFlg",_t[18]);
			_tJ.put("auditLevel",_t[19]);
			_tJ.put("htmlPath",_t[20]);
			_tJ.put("isHeader",_t[21]);
			_tJ.put("createdAt",_t[22]);
			_tJ.put("changedAt",_t[23]);
			if(artType && _t.length==25){
				_tJ.put("artType", _t[24]);
			}
			res.put(_tJ);
		}
		return res;
	}
	public static void main(String[] args){
		String msg = "O.id,O.title,O.subtitle,O.keywords,O.summary,O.specialId,O.artClass,O.artClassName,O.artClassPath,O.indexImg,O.homeImg,O.artResource,O.author,O.commend,O.top,O.hot,O.comment,O.clicks,O.statusFlg,O.auditLevel,O.htmlPath,O.isHeader,O.createdAt,O.changedAt";
		String[] msg_a = msg.split(",");
		for(int i = 0; i < msg_a.length; i++){
			System.out.println("_tJ.put(\""+msg_a[i].split("\\.")[1]+"\",_t["+i+"]);");
		}
		//System.out.println(("O.id".split("\\."))[0]);
	}
}
